﻿Imports System.Net.Mail
Partial Public Class mitglieder_user_erstellen
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim db As New hc_databaseDataContext

        Dim var = (From it In db.Mitgliede_Anwaerter _
                  Where it.Vorname = txt_vorname.Text And it.Nachname = txt_nachname.Text _
                  Select it)
        If var.Count > 0 Then
            Label1.Text = "User existiert bereits"

        Else

            Dim user1 As New Mitgliede_Anwaerter


            Dim a As New Random(10000000)

            Dim b As Int32 = a.Next(5000000, 10000000)
            With user1
                .Vorname = txt_vorname.Text
                .Nachname = txt_nachname.Text
                .Email_HC = txt_email.Text
                .Passwort = "hc"
                .Benutzername = txt_vorname.Text.First + "." + txt_nachname.Text
                .Mitgliedsstatus = dd_status.SelectedItem.Text
            End With

            db.Mitgliede_Anwaerter.InsertOnSubmit(user1)
            db.SubmitChanges()
            Label1.Text = "User erfolgreich erstellt"

        End If

        Dim adresse2 As New MailAddress(txt_email.Text)
        Dim adresse1 As New MailAddress("n.czernig@hanseaticconsulting.de")
        Dim mymsg As MailMessage = New MailMessage(adresse1, adresse2)

        Dim auth As Net.NetworkCredential = New Net.NetworkCredential("5czernig", "scorpi0n")
        Dim mysubject As String = "Info: PMS-Zugang"
        Dim bla As String = "Hallo " + txt_vorname.Text + ", <br> Viel Spass mit dem neuen PMS, bitte trag so schnell wie möglich " _
                       & "deine Daten in dein Mitgliedsprofil ein und ändere dein Passwort.<br>" _
          + "Dein Benutzername : " + txt_vorname.Text.First + "." + txt_nachname.Text + "<br>" _
          + "Dein Passwort: hc" + "<br>" _
          + "Url: www.hanseaticconsultingev.de "

        If Not dd_status.SelectedItem.Text = "Alumni" Then

            With mymsg
                .Subject = mysubject
                .Body = bla
                .IsBodyHtml = True





            End With

            Dim mymail As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("mailhost.informatik.uni-hamburg.de", 25)
            mymail.Credentials = auth
            mymail.EnableSsl = True

            mymail.Send(mymsg)

        End If

    End Sub
End Class